home *** CD-ROM | disk | FTP | other *** search
/ ftp.hitl.washington.edu / ftp.hitl.washington.edu.tar / ftp.hitl.washington.edu / pub / people / tsoper / My Sample Apps / OpenGl3Views / Form1.cs < prev    next >
Text File  |  2005-06-01  |  3KB  |  126 lines

  1. using System;
  2. using System.Drawing;
  3. using System.Collections;
  4. using System.ComponentModel;
  5. using System.Windows.Forms;
  6. using System.Data;
  7. using CsGL.OpenGL;
  8.  
  9. namespace OpenGl3Views
  10. {
  11.     /// <summary>
  12.     /// Summary description for Form1.
  13.     /// </summary>
  14.     public class MainForm : System.Windows.Forms.Form
  15.     {
  16.         /// <summary>
  17.         /// Required designer variable.
  18.         /// </summary>
  19.         /// 
  20.         View view = new View();
  21.         private System.ComponentModel.Container components = null;
  22.  
  23.         public MainForm()
  24.         {
  25.             //
  26.             // Required for Windows Form Designer support
  27.             //
  28.             InitializeComponent();
  29.             Text = "OpenGL 3 Views Example";
  30.             view.SetBounds(10,10,100,100);
  31.             view.Dock = DockStyle.Left;
  32.             view.Dock = DockStyle.Top;
  33.             Controls.Add( view );
  34.  
  35.             //
  36.             // TODO: Add any constructor code after InitializeComponent call
  37.             //
  38.         }
  39.  
  40.         /// <summary>
  41.         /// Clean up any resources being used.
  42.         /// </summary>
  43.         protected override void Dispose( bool disposing )
  44.         {
  45.             if( disposing )
  46.             {
  47.                 if (components != null) 
  48.                 {
  49.                     components.Dispose();
  50.                 }
  51.             }
  52.             base.Dispose( disposing );
  53.         }
  54.  
  55.         #region Windows Form Designer generated code
  56.         /// <summary>
  57.         /// Required method for Designer support - do not modify
  58.         /// the contents of this method with the code editor.
  59.         /// </summary>
  60.         private void InitializeComponent()
  61.         {
  62.             // 
  63.             // MainForm
  64.             // 
  65.             this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
  66.             this.ClientSize = new System.Drawing.Size(292, 266);
  67.             this.Name = "MainForm";
  68.             this.Text = "Form1";
  69.             this.Load += new System.EventHandler(this.Form1_Load);
  70.  
  71.         }
  72.         #endregion
  73.  
  74.         /// <summary>
  75.         /// The main entry point for the application.
  76.         /// </summary>
  77.         [STAThread]
  78.         static void Main() 
  79.         {
  80.             Application.Run(new MainForm());
  81.         }
  82.  
  83.         private void Form1_Load(object sender, System.EventArgs e)
  84.         {
  85.         
  86.         }
  87.     }
  88. }
  89.  
  90. class View : OpenGLControl
  91. {
  92.     public override void glDraw()
  93.     {
  94.         GL.glClear( GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT ); // Clear Screen And Depth Buffer
  95.         GL.glShadeModel( GL.GL_SMOOTH );
  96.  
  97.         CsGL.OpenGL.GLUquadric q = GL.gluNewQuadric();
  98.         int radius;
  99.         radius = 1;
  100.  
  101.         GL.gluQuadricDrawStyle(q,GL.GLU_LINE);
  102.         GL.glColor3f(1,0,0);
  103.         GL.gluSphere(q, radius, 20, 20);
  104.  
  105.         GL.glFlush();
  106.     }
  107.     protected override void InitGLContext()
  108.     {        
  109.         GL.glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );
  110.         GL.glEnable( GL.GL_DEPTH_TEST);
  111.     }
  112.     protected override void OnSizeChanged(EventArgs e)
  113.     {
  114.         base.OnSizeChanged(e);
  115.         GL.glMatrixMode(GL.GL_PROJECTION);
  116.         GL.glLoadIdentity();
  117.         GL.glOrtho( -2,2, -2,2, 0,1000);
  118.         //GL.gluPerspective(90,1, 0.1,1000);
  119.  
  120.         
  121.         GL.glMatrixMode(GL.GL_MODELVIEW );
  122.         GL.glLoadIdentity();
  123.         GL.gluLookAt(0,0,3, 0,0,0, 0,1,0);
  124.     }
  125. }
  126.